package team.knowers.qzh.qzhserver.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import team.knowers.qzh.qzhserver.dao.entity.ChapterDO;
import team.knowers.qzh.qzhserver.dao.entity.CourseDO;
import team.knowers.qzh.qzhserver.dao.mapper.ChapterMapper;
import team.knowers.qzh.qzhserver.dto.resp.ChapterDetailsRespDTO;
import team.knowers.qzh.qzhserver.dto.resp.CourseSearchRespDTO;
import team.knowers.qzh.qzhserver.service.ChapterService;
import team.knowers.qzh.qzhserver.service.CourseService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wutai
 */
@Service
@RequiredArgsConstructor
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterDO> implements ChapterService {
    @Override
    public List<ChapterDetailsRespDTO> getChapterDetailsById(Long id) {
        LambdaQueryWrapper<ChapterDO> queryWrapper = Wrappers.lambdaQuery(ChapterDO.class)
                .eq(ChapterDO::getCourseId, id)
                .eq(ChapterDO::getDelFlag, 0)
                .orderByAsc(ChapterDO::getOrder);
        List<ChapterDO> chapterDOList = baseMapper.selectList(queryWrapper);
        List<ChapterDetailsRespDTO> results = new ArrayList<>();
        for (ChapterDO chapterDO : chapterDOList) {
            results.add(BeanUtil.toBean(chapterDO, ChapterDetailsRespDTO.class));
        }
        return results;
    }

}
